﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class AddTopic : System.Web.UI.Page
{
    Topic topic = new Topic();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] == null)
        {
            Response.Write("<script lanuguage=javascript>alert('请先登录！')</script>");
            Response.Redirect("Login.aspx");
        }
        if (Session["UserName"].ToString() == "Guest")
        {
            Response.Write("<script language=javascript>alert('您无权进行此操作！')</script>");
            Response.Redirect("TopicList.aspx");
        }
    }
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect("TopicList.aspx");
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (txtTopicTitle.Text.Trim() == "")
        {
            Response.Write("<script language=javascript>alert('标题不能为空！')</script>");
        }
        else if (txtTopicContent.Text.Trim() == "")
        {
            Response.Write("<script language=javascript>alert('内容不能为空！')</script>");
        }
        else
        {
            int iResult = topic.AddTopic(Session["UserName"].ToString(),
                txtTopicTitle.Text,txtTopicContent.Text,
                DateTime.Now,Request.UserHostAddress);
            if (iResult > 0)
            {
                Response.Redirect("TopicList.aspx");
            }
            else
            {
                Response.Write("<script language=javascript>alert('发表失败！')</script>");
            }
        }
    }
}
